import Vue from 'vue';
import VueRouter from 'vue-router';
import routes from './router';
import store from './store/';
import {routerMode} from './config/env';
import './config/rem';
import FastClick from 'fastclick';
import './assets/style/swiper.min.css';
import 'fetch-polyfill';
import wx from 'weixin-js-sdk';
import VueAwesomeSwiper from 'vue-awesome-swiper'
import {stringUtil,wxShare} from './assets/js/common';
import Mint from 'mint-ui';
import 'mint-ui/lib/style.css';
import wxService from "./service/wxService";

//import App from './App.vue';
if ('addEventListener' in document) {
    document.addEventListener('DOMContentLoaded', function() {
        FastClick.attach(document.body);
    }, false);
}
Vue.use(VueAwesomeSwiper);
Vue.use(VueRouter);
Vue.use(Mint);

const router = new VueRouter({
	routes,
	mode: routerMode,
	strict: process.env.NODE_ENV !== 'production'
})


new Vue({
	router,
	store,
    beforeCreate(){
        var openid = window.sessionStorage.getItem("beansOpenid") || "",
            code = stringUtil.getQueryValue("code") || "";
        if(!/5beans/.test(location.href)) {
            openid = "opMhF00riczyMWzLJILeglew11m0";
        }
        if(openid == "") {
            if(code == "") {
                var h = encodeURIComponent(location.href);
                location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxf3e807fb8699fcf2&redirect_uri="+h+"&response_type=code&scope=snsapi_base&state=123#wechat_redirect";
                return;
            } else
            {
                // diaoyong jiekou 获取openid
                wxService.getOpenid({code:code})
                .then(data => {
                    if(data.code == "201") {
                        window.sessionStorage.setItem("beansOpenid",data.info);
                       // this.$router.push({path:"/main"});
                    } else {
                        //Mint.toast(""+data.msg);
                    }

                });
            }
        } else {
        	window.sessionStorage.setItem("beansOpenid",openid);
           // this.$router.push({path:"/main"});
        }
    },
    mounted() {
        wxShare(wx);
    }
}).$mount('#app')
